import Vue from 'vue'
import {
  getToken,
  getCsrfToken
} from '@/utils/auth'
import Utils from '@/libs/framework/util'
import Constant from '@/libs/framework/constant'
import qs from 'qs'

import Framework7 from 'framework7/framework7-lite.esm.bundle.js'
import Framework7Vue from 'framework7-vue/framework7-vue.esm.bundle.js'
import 'framework7/css/framework7.bundle.css';


const baseURL = process.env.VUE_APP_BASE_API

Framework7.use(Framework7Vue);
Framework7.request.setup({
  timeout: 15000,
  beforeCreate(options) {
    if (options.url && options.url.startsWith('/api')) {
      options.url = options.url.replace(/\/api/, '/mobileApi');
    }
    if (options.url && !options.url.startsWith(baseURL)) {
      options.url = baseURL + options.url;
    }
  },
  beforeSend: function (xhr, options) {
    let csrfToken = getCsrfToken();
    if (csrfToken) {
      xhr.setRequestHeader(Constant.token.csrfToken, csrfToken);
    }
  },
  error: function error(xhr) {},
  complete: function complete(xhr) {},
  success: function (result, status, xhr) {},
});

// Vue.prototype.$7 = Framework7;
